package com.example.bookmanage.controller;

import com.example.bookmanage.domain.TableDataInfo;
import com.example.bookmanage.result.Result;
import com.github.pagehelper.PageInfo;

import java.util.List;

public class BaseController {

    public Result<?> toResult(int rows) {
        return rows > 0 ? Result.success() : Result.fail();
    }

    public Result<?> toResult(boolean flg) {
        return flg ? Result.success() : Result.fail();
    }

    /**
     * 封装分页数据
     * 
     *
     * @param list
     * @return
     */
    public TableDataInfo getTableDataInfo(List<?> list) {

        if (list == null || list.isEmpty()) {
            return TableDataInfo.empty();
            
        }
        // total表示总数
        long total = new PageInfo<>(list).getTotal();
        return TableDataInfo.success(list, total);
    }

}
